Install @nestjs/mongoose and mongoose, then import MongooseModule.forRoot() in AppModule. Define schemas using @Schema() and @Prop() decorators on classes and generate the schema with SchemaFactory.createForClass(). Register schemas in feature modules with MongooseModule.forFeature() and inject the model with @InjectModel().
@Schema({ timestamps: true }) automatically adds createdAt and updatedAt fields to every document.
SchemaFactory.createForClass(User) generates the Mongoose schema from the decorated class.
MongooseModule.forFeature() registers the model for the feature module's DI scope.
@InjectModel(User.name) injects the Mongoose Model — always use the class .name property, not a string literal.
HydratedDocument<User> is the correct type for a Mongoose document with instance methods.